// utils/message.js - 消息提示工具
export default {
  // 成功提示
  success(message, duration = 2000) {
    if (!message) return
    uni.showToast({
      title: message,
      icon: 'success',
      duration
    })
  },
  
  // 错误提示
  error(message, duration = 2000) {
    if (!message) return
    uni.showToast({
      title: message,
      icon: 'error',
      duration
    })
  },
  
  // 普通提示
  info(message, duration = 2000) {
    if (!message) return
    uni.showToast({
      title: message,
      icon: 'none',
      duration
    })
  },
  
  // 加载提示
  loading(message = '加载中...') {
    uni.showLoading({
      title: message,
      mask: true
    })
  },
  
  // 隐藏加载提示
  hideLoading() {
    uni.hideLoading()
  },
  
  // 确认弹窗
  confirm(content, options = {}) {
    return new Promise((resolve, reject) => {
      uni.showModal({
        title: options.title || '提示',
        content,
        showCancel: options.showCancel !== false,
        cancelText: options.cancelText || '取消',
        confirmText: options.confirmText || '确定',
        success: (res) => {
          if (res.confirm) {
            resolve(true)
          } else {
            resolve(false)
          }
        },
        fail: () => {
          reject(new Error('Modal failed'))
        }
      })
    })
  }
}